#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int sumdivisors(const int n)
{
	int c = 1;
	int last = (int)sqrt(n);
	for (long i=2;i<=last;i++)
	{
		if (n%i) continue;
		c+=i;
		int t = n/i;
		if (t > i) c+=t;
	}
	return c;
}

int main()
{
	const int X = 10000;
	int result = 0;

	int * d = new int [X];
	fill (d,d+X,0);

	for(int i=2; i<X; i++)
	{
		if(d[i] != 0) continue;
		d[i] = sumdivisors(i);

		for(int j = i; d[j] < X && d[d[j]] == 0; j = d[j])
		{
			d[d[j]] = sumdivisors(d[j]);
			if(j == d[d[j]])
				result += j+d[j];
		}
	}

	cout << result << endl;

	return 0;
}
